<template>
  <div class="user">
    <el-col :span="24">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>用户管理</el-breadcrumb-item>
        <el-breadcrumb-item>用户列表</el-breadcrumb-item>
      </el-breadcrumb>
    </el-col>
    <el-col :span="24" class="user-content">
      <!-- 输入框 -->
      <el-col :span="6">
        <el-col :span="18">
          <el-input placeholder="请输入用户名" prefix-icon="el-icon-search"></el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary">搜索</el-button>
        </el-col>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click="isShow = true">添加用户</el-button>
      </el-col>
      <el-col :span="24">
        <el-table :data="arr.users" border style="width: 100%">
          <el-table-column prop="id" label="id" width="140">
          </el-table-column>
          <el-table-column prop="username" label="姓名" width="140">
          </el-table-column>
          <el-table-column prop="email" label="邮箱" width="200">
          </el-table-column>
          <el-table-column prop="create_time" label="电话" width="140">
          </el-table-column>
          <el-table-column prop="role_name" label="角色" width="140">
          </el-table-column>
          <el-table-column prop="mg_state" label="状态" width="140">
          </el-table-column>
          <el-table-column label="操作" width="300">
            <template slot-scope="scope">
              <el-button type="primary">编辑</el-button>
              <el-button type="danger">删除</el-button>
              <el-button type="info">设置</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="9" style="margin-top: 20px;">
        <div class="block">
          <el-pagination :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
          </el-pagination>
        </div>
      </el-col>
    </el-col>
    <transition name="fade-down" mode="out-in">
      <el-form label-width="100px" class="user-form" v-show="isShow" key="user-form">
        <!-- 标题 -->
        <p>添加用户</p>
        <el-form-item label="用户名" prop="username">
          <el-input type="text" autocomplete="off"></el-input>
          <span>用户名不能少于6位</span>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" autocomplete="off"></el-input>
          <span>密码不能少于6位</span>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input type="email" autocomplete="off"></el-input>
          <span>请输入正确的邮箱格式</span>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input type="number"></el-input>
          <span>请输入正确的手机号格式</span>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">提交</el-button>
          <el-button>重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 遮罩层 -->
      <div class="mask " v-show="isShow"></div>
  </div>
</template>

  <style scoped lang="scss">
  .user-content {
    margin: 20px;
    background-color: #fff;
    height: 800px;
    padding-left: 50px;

  }

  ::v-deep .el-table__header thead tr th {
    height: 30px !important;
    line-height: 30px;
  }

  .user-form {
    width: 600px;
    height: 500px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    // align-items: center;
    background-color: #fff;
    position: fixed;
    text-align: left;
    padding-right: 30px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 10px;
    z-index: 4;

    p {
      line-height: 20px;
      margin-left: 30px;
    }

    span {
      display: block;
      height: 20px;
    }


  }

  .mask {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 3;
  }
</style>
  <script>
  import axios from 'axios';
  export default {
    data() {
      return {
        arr: [],
        baseURL: 'http://43.138.15.137:7000/api/private/v1',
        token: localStorage.getItem('token'),
        pagesize: 8,
        pagenum: 1,
        isShow: false
      }
    },
    created() {
      axios.get(this.baseURL + '/users', {
        headers: {
          'Authorization': this.token
        },
        params: {
          pagesize: this.pagesize,
          pagenum: this.pagenum
        }
      }).then(res => {
        let { data: { data, meta } } = res
        this.arr = data
      })
    }
  }

</script>